/*
Copyright (c) 2013, trixpro.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
    this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, 
    this list of condit
    and/or other materials provided with the distribution.
    * Neither the name of the trixpro.com, Inc. nor the names of its contributors 
    may be used to endorse or promote products derived from this software 
    without specific prior written permission.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
OF THE POSSIBILITY OF SUCH DAMAGE.
*/

@isTest
public class TestUtils {

	public Account 	aAccount		{get; set;}
	public Contact 		aContac			{get; set;}
	public Attachment 	aAttachment		{get; set;}
	public Opportunity 	aOpportunity		{get; set;}
	public Task 	aTask		{get; set;}
	public User 	aUser		{get; set;}
	public TradeTerm__c 	aTradeTerm {get; set;}
	
	
	public static TestUtils generateTest(){
		TestUtils e = new TestUtils();
		return e;
	}
	
	public void generateAccount(){
    this.aAccount 				= new Account();
    this.aAccount.Name 		= 'Test';	    
    insert this.aAccount;
	}
	
	public void generateContact(){
	    this.aContac 				= new Contact();
	    this.aContac.firstName 		= 'Test';
	    this.aContac.LastName 		= 'Test'; 	    
	    insert this.aContac;
	    this.aAttachment = new Attachment();
	    this.aAttachment.Body = Blob.valueOf('String');
	}
	
	public void generateOpportunity(){
    this.aOpportunity 				= new Opportunity();
    this.aOpportunity.Name 		= 'Test';	    
    this.aOpportunity.AccountId 		= this.aAccount.id;	    
    this.aOpportunity.closeDate 		= date.valueOf('2013-01-01');	    
    this.aOpportunity.stageName 		= 'CloseWin';	    
    insert this.aOpportunity;
	}
	
	public void generateTask(){
		  this.aTask = new Task();
	    this.aTask.OwnerId = UserInfo.getUserId();
	    this.aTask.Subject = 'test';
	    this.aTask.priority='Normal';
	    this.aTask.status = '进行中';
	    this.aTask.description = 'test';	 
	    this.aTask.activityDate =date.today();
    	insert this.aTask;
	}
	
	public void generateTradeTerm(){
		aTradeTerm=new TradeTerm__c(Name='TestPort');
		aTradeTerm.EXW__c=1.99;
		aTradeTerm.CFR__c=2.99;
		aTradeTerm.CIF__c=3.99;
		aTradeTerm.CIP__c=4.99;
		aTradeTerm.CPT__c=5.99;
		aTradeTerm.DAF__c=6.99;
		aTradeTerm.DDP__c=7.99;
		aTradeTerm.DDU__c=8.99;
		aTradeTerm.DEQ__c=9.99;
		aTradeTerm.DES__c=10.99;
		aTradeTerm.FAS__c=11.99;
		aTradeTerm.FCA__c=12.99;
		aTradeTerm.FOB__c=13.99;
    insert this.aTradeTerm;
	}
	
	public void makeUser() {
		Profile p = [select id from profile where name='System Administrator'];
		String name = 'test' + Math.random() + '@example.org';
		aUser = new User(
			alias = 'testuser',
			email=name,
			emailencodingkey='UTF-8',
			lastname='Testing',
			languagelocalekey='en_US',
			localesidkey='en_US',
			profileid = p.id,
			timezonesidkey='America/Los_Angeles',
			username=name,
			communityNickname = 'test' + Math.random()
		);
		insert aUser;
	}
}